Overriding a method just to call the overridden function from the base class without performing any other actions can be useless and
misleading.
There are cases when it is justified because redeclaring the function allows some side effects:
- if a type (return type or a parameter type) is not exactly the same as the super member
- if the covariant keyword is added to one of the parameters
- if documentation comments are present on the member
- if the member has annotations other than
@override
- if the member is not annotated with
@protected
, and the super member is
Noncompliant code example
class Child extends Parent {
@override
void foo() {
super.foo();
}
}
Compliant solution
class Child extends Parent {
@override
void foo() {
bar();
}
}